package DHBW.Convert;

import DHBW.Convert.CharConverter;
import android.util.Log;

/**
 * The MessageConverter is used to convert data to be sent via bluetooth
 * @author baumlndn
 *
 */
public class MessageConverter {
   
	/**
	 * Convert function
	 * @param buffer data to be converted to a message block
	 * @param laenge length of the given data
	 * @return complete message including Start- and Endbyte
	 */
	public static byte[] convertOut(byte[] buffer, int laenge) {
    	byte[] abc = new byte[laenge+2];
    	String tmp_out = "0x10 ";
    	abc[0] = 0x10;
    	
    	for (int i=1;i<=laenge;i++) {
    		abc[i] = (byte) (buffer[i-1]);
    		tmp_out = tmp_out+" "+CharConverter.byte2HexStr(abc[i]);
    	}
    	abc[laenge+1] = 0x0D;
    	tmp_out = tmp_out+" 0x0D";
    	Log.d("MessageConverter","MsgConv: "+tmp_out);
    	return abc;        	
    }
}
